Passed
Push — main ( c3163a...9d001c )
by Andrii
03:28
created

mix.ts ➔ classNaming   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
1
import { ClassHash } from "../../src/main.types"
2
3
type Props = {
4
  Btn: ClassHash
5
  isValid: boolean
6
  isOpen?: boolean
7
}
8
9
const {
10
  Btn,
11
  isOpen,
12
  isValid
13
} = {} as Props
14
15
classNaming(
16
  guard1({Btn, Btn__Open: isOpen, Btn__Valid: isValid})
17
)
18
//@ts-expect-error
19
guard2({Btn, Btn__Open: isOpen, Btn__Valid: isValid})
20
21
function guard1<
22
  E extends Record<string, ClassHash|boolean>
23
>(source: E) {
24
  return source as unknown as {[K in keyof E]: E[K] extends boolean ? boolean : E[K] extends ClassHash ? ClassHash : never}
25
}
26
27
function guard2<T>(source: T extends Record<infer K, ClassHash|boolean> ? {
28
  [k in K]: T[k] extends boolean ? T[k] : T[k] extends ClassHash ? T[k] : never
29
 } : never) {
30
  return source
31
}
32
33
function classNaming<T>(source: T) {
34
  return source
35
}